/**
 * 
 * Copyright (C) 2011 Cody Stoutenburg . All rights reserved.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * 
 */
package net.alteiar.behaviours.basic;

import jade.lang.acl.ACLMessage;
import jade.proto.SimpleAchieveREInitiator;

import java.util.Vector;

import net.alteiar.agent.GamePlayerAgent;

/**
 * @author Cody Stoutenburg
 * 
 */
public abstract class GameCommunicationInitiator extends
		SimpleAchieveREInitiator {
	private static final long serialVersionUID = 1L;

	/*
	 * This protocol work in that way: - send message (constructor) 
	 * - wait for reply 
	 * 		- not-understood 
	 * 		- refuse 
	 * 		- agree
	 * 		
	 */

	/**
	 * @param a
	 * @param msg
	 */
	public GameCommunicationInitiator(GamePlayerAgent a, ACLMessage msg) {
		super(a, msg);
	}

	protected GamePlayerAgent getMyAgent() {
		return (GamePlayerAgent) myAgent;
	}

	/**
	 * This method is called every time an <code>agree</code> message is
	 * received, which is not out-of-sequence according to the protocol rules.
	 * This default implementation does nothing; programmers might wish to
	 * override the method in case they need to react to this event.
	 * 
	 * @param agree
	 *            the received agree message
	 **/
	@Override
	protected abstract void handleAgree(ACLMessage agree);

	/**
	 * This method is called every time a <code>refuse</code> message is
	 * received, which is not out-of-sequence according to the protocol rules.
	 * This default implementation does nothing; programmers might wish to
	 * override the method in case they need to react to this event.
	 * 
	 * @param refuse
	 *            the received refuse message
	 **/
	@Override
	protected abstract void handleRefuse(ACLMessage refuse);

	/**
	 * This method is called every time a <code>inform</code> message is
	 * received, which is not out-of-sequence according to the protocol rules.
	 * This default implementation does nothing; programmers might wish to
	 * override the method in case they need to react to this event.
	 * 
	 * @param inform
	 *            the received inform message
	 **/
	@Override
	protected abstract void handleInform(ACLMessage inform);

	/**
	 * This method is called when all the responses have been collected or when
	 * the timeout is expired. The used timeout is the minimum value of the slot
	 * <code>replyBy</code> of all the sent messages. By response message we
	 * intend here all the <code>agree, not-understood,
	 * refuse</code> received messages, which are not not out-of-sequence
	 * according to the protocol rules. This default implementation does
	 * nothing; programmers might wish to override the method in case they need
	 * to react to this event by analysing all the messages in just one call.
	 * 
	 * @param responses
	 *            the Vector of ACLMessage objects that have been received
	 **/
	@Override
	protected void handleAllResponses(Vector responses) {
	}

	/**
	 * This method is called when all the result notification messages have been
	 * collected. By result notification message we intend here all the
	 * <code>inform, 
	 * failure</code> received messages, which are not not out-of-sequence
	 * according to the protocol rules. This default implementation does
	 * nothing; programmers might wish to override the method in case they need
	 * to react to this event by analysing all the messages in just one call.
	 * 
	 * @param resultNodifications
	 *            the Vector of ACLMessage object received
	 **/
	@Override
	protected void handleAllResultNotifications(Vector resultNotifications) {
	}
}
